Binary Search Visualization

About Binary Search

Binary Search is an efficient algorithm for finding an item from a sorted list of items.

It works by repeatedly dividing the search interval in half until the target value is found or the interval is empty.

(Between 5 and 25 elements. Array is automatically sorted!)

Search Range: [0, 14]
Middle Index: -
Middle Value: -
Array Size
15
Comparisons
0
Steps
0
Time Taken
0ms
Generate a sorted array and enter a number to search
Search Result
No search performed yet
Time Complexity
Best Case: O(1)
Average Case: O(log n)
Worst Case: O(log n)
Space Complexity: O(1) - Iterative
Space Complexity: O(log n) - Recursive
Normal Element
Visited Element
Low Pointer
Middle Pointer
High Pointer
Found Element

Binary Search Algorithm Steps

1
Set low = 0 and high = n-1, where n is the array size
2
While low <= high, calculate mid = floor((low + high) / 2)
3
If array[mid] == target, return mid (element found)
4
If array[mid] < target, set low = mid + 1 (search right half)
5
If array[mid] > target, set high = mid - 1 (search left half)
6
If low > high, element not found